package com.liu.algorithm.strategy;

import java.util.Comparator;
import java.util.Random;

/**
 * 开闭原则  对扩展开放对修改关闭，即在不改变本身代码的情况下其行为能扩
 *
 * @author LIU
 * @version 1.0
 * @description: 策略模式
 * @date 2022/8/25 11:20
 */
public class Main {
    public static void main(String[] args) {
        int length = 10;
        Cat[] cats = new Cat[length];
        Random random = new Random();
        for (int i = 0; i <length ; i++) {
            Cat cat = new Cat();
            cat.setHeight(random.nextInt(30));
            cats[i]=cat;
        }

//        Sorter.sort(cats);

        // 比较方法和实体类分类
        Sorter2<Cat> sorter2 = new Sorter2<>();
//        sorter2.sort(cats,new CatHeightComparator());
        //函数式编程
//        sorter2.sort(cats,(o1,o2)->{
//            return Integer.compare(o1.getHeight(), o2.getHeight());
//        });
        sorter2.sort(cats, Comparator.comparingInt(Cat::getHeight));
        for (Cat cat : cats) {
            System.out.println(cat.toString());
        }
    }
}
